package org.singledog.form.builder.parser.freemarker.parser;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.singledog.form.builder.ComponentType;
import org.singledog.form.builder.parser.freemarker.view.FormView;
import org.singledog.form.builder.view.View;

/**
 * @author adam
 * @date 2019/5/1
 */
public class FormComponentParser extends AbstractFreemarkerParser {
	@Override
	public ComponentType supportType() {
		return ComponentType.form;
	}

	/**
	 * 1. read form schema based version
	 * 2. build View
	 * @param code component code
	 * @return
	 */
	@Override
	public View parseView(String code) {
		String schema = getSchema(code);
		JSONObject object = JSON.parseObject(schema);
		return new FormView(code, object);
	}
}
